package com.bool.example.modules.user.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bool.core.api.dto.PagingReqDTO;
import com.bool.example.modules.user.dto.SysUserDTO;
import com.bool.example.modules.user.entity.SysUser;
import com.bool.example.modules.user.mapper.SysUserMapper;
import com.bool.example.modules.user.service.SysUserService;
import org.springframework.stereotype.Service;

/**
* <p>
* 用户表业务实现类
* </p>
*
* @author 聪明笨狗
* @since 2020-08-11 11:32
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public IPage<SysUserDTO> paging(PagingReqDTO<SysUserDTO> reqDTO) {

        // 创建分页对象
        Page query = new Page(reqDTO.getCurrent(), reqDTO.getSize());


        //查询条件
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();

        // 请求参数
        SysUserDTO params = reqDTO.getParams();


        //获得数据
        IPage<SysUser> page = this.page(query, wrapper);
        //转换结果
        IPage<SysUserDTO> pageData = JSON.parseObject(JSON.toJSONString(page), new TypeReference<Page<SysUserDTO>>(){});
        return pageData;
     }
}
